﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace WorkingTitleDungeonCrawler
{
    class Player : MovingGameObj
    {
        // Constructor
        public Player()
        {
            MaxSpeed = 1.0F;
            ShotPower = 0;
            Life = 100F;
            Frame = 0;
            Angle = (float)(Math.PI / 2);

        }

        // Properties
        public float MaxSpeed { get; set; }
        public float ShotPower { get; set; }
        public int WeaponType { get; set; }
        public bool ShotFired { get; set; }
        public float Life { get; set; }
        public int Frame { get; set; }

        float timer = 1.8F;
        const float TIMER = 1.8F;
        

        //Methods

        /// <summary>
        /// Player Movement logic. The Player is moved around with the arrow keys.
        /// </summary>
        /// <param name="gameTime"></param>
        public override void Update(GameTime gameTime)
        {
            
            KeyboardState ks = Keyboard.GetState();
            float elapsed = (float)gameTime.ElapsedGameTime.TotalSeconds;
            timer -= elapsed;

            if (ks.IsKeyDown(Keys.Up))
            {
                Frame = 1;
                Speed = MaxSpeed;
                Angle = -(float)(Math.PI/2);
            }
             else if (ks.IsKeyDown(Keys.Down))
            {
                Frame = 0;
                Speed = MaxSpeed;
                Angle = (float)(Math.PI/2);
            }
            else if (ks.IsKeyDown(Keys.Left))
            {
                Frame = 2;
                Speed = MaxSpeed;
                Angle = (float)(Math.PI);
            }
            else if (ks.IsKeyDown(Keys.Right))
            {
                Frame = 3;
                Speed = MaxSpeed;
                Angle = (float)(2 * Math.PI);
            }
            else
            {
                Speed = 0;
            }

            if (ks.IsKeyDown(Keys.Space))
            {

                
                if (timer < 1)
                {
                    ShotPower = 50;
                    ShotFired = true;
                    timer = TIMER;
                }
            }

            Direction = new Vector2((float)(Math.Cos(Angle)), (float)(Math.Sin(Angle)));

            base.Update(gameTime);
           
        }

        public override void Draw(SpriteBatch spritebatch, Vector2 DrawOffset)
        {
            Rectangle tmp = new Rectangle((Frame % 1 ) * 48, Frame * 48, 48, 48);

            spritebatch.Draw(Gfx, Position - DrawOffset + new Vector2(475, 300), tmp,
                     Color.White, 0, new Vector2(Gfx.Height / 2, Gfx.Width / 2), 1.0F,
                     SpriteEffects.None, 0);
        }

       

    }
}
